#!/bin/bash

# 手动修复关键的分页问题文件

echo "开始手动修复关键的分页问题文件..."
echo "=========================================="

# 修复 UserActionServiceImpl.java
echo "修复 UserActionServiceImpl.java..."
sed -i.bak '
/PaginationRequest.*paginationRequest/,/return paginationResponse/ {
    s/List<MtUserAction> dataList = mtUserActionMapper\.selectList(lambdaQueryWrapper);/Page<MtUserAction> page = new Page<>(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());\
        Page<MtUserAction> pageResult = mtUserActionMapper.selectPage(page, lambdaQueryWrapper);\
        List<MtUserAction> dataList = pageResult.getRecords();/
    /PageRequest pageRequest = PageRequest\.of/d
    /PageImpl pageImpl = new PageImpl/d
    s/new PaginationResponse(pageImpl,/new PaginationResponse(pageResult,/
    /paginationResponse\.setTotalPages/d
    /paginationResponse\.setTotalElements/d
    /paginationResponse\.setContent/d
    s/PaginationResponse<MtUserAction> paginationResponse = new PaginationResponse(pageResult, MtUserAction\.class);.*return paginationResponse;/return PaginationHelper.convertToPaginationResponse(dataList, (int)pageResult.getCurrent(), (int)pageResult.getSize(), pageResult.getTotal(), MtUserAction.class);/
}
' fuint-application/src/main/java/com/fuint/common/service/impl/UserActionServiceImpl.java

# 修复 SendSmsServiceImpl.java
echo "修复 SendSmsServiceImpl.java..."
sed -i.bak '
/PaginationRequest.*paginationRequest/,/return paginationResponse/ {
    s/List<MtSmsSendedLog> dataList = mtSmsSendedLogMapper\.selectList(lambdaQueryWrapper);/Page<MtSmsSendedLog> page = new Page<>(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());\
        Page<MtSmsSendedLog> pageResult = mtSmsSendedLogMapper.selectPage(page, lambdaQueryWrapper);\
        List<MtSmsSendedLog> dataList = pageResult.getRecords();/
    /PageRequest pageRequest = PageRequest\.of/d
    /PageImpl pageImpl = new PageImpl/d
    s/new PaginationResponse(pageImpl,/new PaginationResponse(pageResult,/
    /paginationResponse\.setTotalPages/d
    /paginationResponse\.setTotalElements/d
    /paginationResponse\.setContent/d
    s/PaginationResponse<MtSmsSendedLog> paginationResponse = new PaginationResponse(pageResult, MtSmsSendedLog\.class);.*return paginationResponse;/return PaginationHelper.convertToPaginationResponse(dataList, (int)pageResult.getCurrent(), (int)pageResult.getSize(), pageResult.getTotal(), MtSmsSendedLog.class);/
}
' fuint-application/src/main/java/com/fuint/common/service/impl/SendSmsServiceImpl.java

# 修复 BannerServiceImpl.java
echo "修复 BannerServiceImpl.java..."
sed -i.bak '
/PaginationRequest.*paginationRequest/,/return paginationResponse/ {
    s/List<MtBanner> dataList = mtBannerMapper\.selectList(lambdaQueryWrapper);/Page<MtBanner> page = new Page<>(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());\
        Page<MtBanner> pageResult = mtBannerMapper.selectPage(page, lambdaQueryWrapper);\
        List<MtBanner> dataList = pageResult.getRecords();/
    /PageRequest pageRequest = PageRequest\.of/d
    /PageImpl pageImpl = new PageImpl/d
    s/new PaginationResponse(pageImpl,/new PaginationResponse(pageResult,/
    /paginationResponse\.setTotalPages/d
    /paginationResponse\.setTotalElements/d
    /paginationResponse\.setContent/d
    s/PaginationResponse<MtBanner> paginationResponse = new PaginationResponse(pageResult, MtBanner\.class);.*return paginationResponse;/return PaginationHelper.convertToPaginationResponse(dataList, (int)pageResult.getCurrent(), (int)pageResult.getSize(), pageResult.getTotal(), MtBanner.class);/
}
' fuint-application/src/main/java/com/fuint/common/service/impl/BannerServiceImpl.java

# 修复 SmsTemplateServiceImpl.java
echo "修复 SmsTemplateServiceImpl.java..."
sed -i.bak '
/PaginationRequest.*paginationRequest/,/return.*paginationResponse/ {
    s/List<MtSmsTemplate> dataList = mtSmsTemplateMapper\.selectList(lambdaQueryWrapper);/Page<MtSmsTemplate> page = new Page<>(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());\
        Page<MtSmsTemplate> pageResult = mtSmsTemplateMapper.selectPage(page, lambdaQueryWrapper);\
        List<MtSmsTemplate> dataList = pageResult.getRecords();/
    /PageRequest pageRequest = PageRequest\.of/d
    /PageImpl pageImpl = new PageImpl/d
    s/return PaginationHelper\.convertToPaginationResponse(dataList, paginationRequest\.getCurrentPage(), paginationRequest\.getPageSize(), pageResult\.getTotal(), MtSmsTemplate\.class);/return PaginationHelper.convertToPaginationResponse(dataList, (int)pageResult.getCurrent(), (int)pageResult.getSize(), pageResult.getTotal(), MtSmsTemplate.class);/
}
' fuint-application/src/main/java/com/fuint/common/service/impl/SmsTemplateServiceImpl.java

echo ""
echo "手动修复完成！"
echo "=========================================="
echo "请运行以下命令验证修复结果："
echo "bash check_selectlist_in_pagination.sh"
